<?php
/*
 * @Author       : chaihao
 * @Date         : 2020-06-04 09:47:57
 * @FilePath     : /ai/controllers/api/AnimationController.php
 */

namespace app\controllers\api;

use app\commands\ErrorMsg;
use app\commands\Helper;
use app\commands\Validator;
use app\Services\api\AnimationService;

class AnimationController extends ApiController
{

    /**
     *  返回当前流地址
     */
    public function actionGetSteaming()
    {
        $req = $this->req;
        $rules = array(
            'roomid'  => 'required|integer',
        );
        Validator::validator($req, $rules, ErrorMsg::ERROR_MSG);
        $res = AnimationService::getInstance()->getSteaming($req);
        Helper::right_out($req, $res);
    }

    /**
     *  新增动作请求
     */
    public function actionSaveAnimation()
    {
        $req = $this->req;
        $rules = array(
            'roomid'  => 'required|integer',
            'row'  => 'required|integer',
            'col'  => 'required|integer',
            'status'  => 'required|integer',
            'updatetime'  => 'required',
        );
        Validator::validator($req, $rules, ErrorMsg::ERROR_MSG);
        $req['user_id'] = $req['userid'] ?? $this->user->ID;
        $res = AnimationService::getInstance()->saveAnimation($req);
        Helper::right_out($req, $res);
    }

    /**
     *  查询新的动作（返回比传参updatetime更新的所有动作信息）w
     */
    public function actionCheckAnimation()
    {
        $req = $this->req;
        $rules = array(
            'roomid'  => 'required|integer',
            'updatetime'  => 'required',
        );
        Validator::validator($req, $rules, ErrorMsg::ERROR_MSG);
        $res = AnimationService::getInstance()->checkAnimation($req);
        Helper::right_out($req, $res);
    }
}
